<?php
// 测试数据库连接
require_once 'utils/Database.php';
require_once 'utils/Response.php';

try {
    $db = new Database();
    
    // 测试查询
    $users = $db->fetchAll("SELECT id, nickname, phone, avatar FROM users LIMIT 5");
    
    echo "<h2>数据库连接测试</h2>";
    echo "<p>连接成功！</p>";
    echo "<h3>用户表前5条记录：</h3>";
    echo "<pre>" . print_r($users, true) . "</pre>";
    
    // 测试更新
    if (!empty($users)) {
        $testUserId = $users[0]['id'];
        $testUpdateData = [
            'nickname' => 'Test Update ' . date('Y-m-d H:i:s'),
            'updated_at' => date('Y-m-d H:i:s')
        ];
        
        echo "<h3>测试更新用户ID: " . $testUserId . "</h3>";
        echo "<p>更新数据: " . json_encode($testUpdateData) . "</p>";
        
        $result = $db->update('users', $testUpdateData, 'id = :user_id', ['user_id' => $testUserId]);
        echo "<p>更新结果: " . ($result ? '成功' : '失败') . "</p>";
        
        // 检查更新后的数据
        $updatedUser = $db->fetchOne("SELECT * FROM users WHERE id = ?", [$testUserId]);
        echo "<p>更新后的用户数据:</p>";
        echo "<pre>" . print_r($updatedUser, true) . "</pre>";
    }
    
} catch (Exception $e) {
    echo "<h2>数据库连接失败</h2>";
    echo "<p>错误: " . $e->getMessage() . "</p>";
}

// 显示PHP错误日志位置
echo "<h3>PHP配置信息:</h3>";
echo "<p>Error Log: " . ini_get('error_log') . "</p>";
echo "<p>Log Errors: " . (ini_get('log_errors') ? '开启' : '关闭') . "</p>";
echo "<p>Display Errors: " . (ini_get('display_errors') ? '开启' : '关闭') . "</p>";
?>